﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SoilProfiler
{
    public partial class ProjectionDatum : Form
    {
        public ProjectionDatum()
        {
            InitializeComponent();

            for (int i = 1; i <= 60; i++)
            {
                uxNumber.Items.Add(i.ToString());
            }
            uxNumber.SelectedIndex = 13;
            uxHemispher.SelectedIndex = 0;


        }
        public string Projection { set; get; }
        private void uxAccept_Click(object sender, EventArgs e)
        {
            if (uxOptionProjected.Checked)
            {
                if (uxHemispher.Text != "" && uxNumber.Text != "")
                {
                    if (uxHemispher.Text == "North")
                        Projection = "+proj=utm +zone=" + uxNumber.Text + " +ellps=WGS84 +datum=WGS84 +units=m +no_defs ";
                    else
                        Projection = "+proj=utm +zone=" + uxNumber.Text + " +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs ";

                }
                else
                {
                    MessageBox.Show("Please select a zone and hemisphere");
                    return;
                }
                Close();
            }
            else if (uxProjectFile.Checked)
            {
                if (uxFileName.Text != "")
                {
                    if (!File.Exists(uxFileName.Text))
                    {
                        MessageBox.Show("Please select a .prj file");

                    }
                    else
                        Close();


                }
                  


            }else
            {
              Projection = "+ellps=WGS84 +datum=WGS84 +units=m +no_defs ";
                Close();
            }
        }

        private void uxBrowse2_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                uxFileName.Text = openFileDialog1.FileName;
                if (File.Exists(uxFileName.Text))
                Projection = File.ReadAllLines(uxFileName.Text)[0];
            }
        }

        private void uxOptionProjected_CheckedChanged(object sender, EventArgs e)
        {
            uxProjected.Visible = true;
            uxFileName.Enabled = false;
            uxBrowse2.Enabled = false;
        }

        private void uxOptionWGS84_CheckedChanged(object sender, EventArgs e)
        {
            uxProjected.Visible = false;
            uxFileName.Enabled = false;
            uxBrowse2.Enabled = false;
        }

        private void uxProjectFile_CheckedChanged(object sender, EventArgs e)
        {
            uxFileName.Enabled = true;
            uxBrowse2.Enabled = true;
            uxProjected.Visible = false;
        }

        private void uxCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
